#!/bin/bash

scriptPath=$(dirname $0);
echo "intercontact time analysis (contactIntercontact.eps)"

cat $scriptPath/intercontact-gnuplot.begin > intercontact.gplot
echo "" > tmp-intercontact-all

sqlite3 -batch -separator ' ' trace.sqlite "SELECT time, device, interfaceId, eventName FROM events WHERE eventName='EVENT_TYPE_NEIGHBOR_INTERFACE_UP' OR eventName='EVENT_TYPE_NEIGHBOR_INTERFACE_DOWN' ORDER BY device, interfaceId, time" > tmp-intercontact-sql

cat tmp-intercontact-sql | awk -f $scriptPath/intercontact.awk > tmp-intercontact-all
cat tmp-intercontact-all | sort -n | awk '{print $1, FNR}' > tmp-intercontact-all-cdf

numLines=$(wc -l tmp-intercontact-all-cdf | awk '{print $1;}')
PLOT="\"tmp-intercontact-all-cdf\" using 1:(1-\$2/"$numLines") with linespoints ls $i+1 notitle,"

PLOT=`echo $PLOT | sed -e 's/,$//'`
echo "plot "$PLOT >> intercontact.gplot

gnuplot intercontact.gplot

rm intercontact.gplot
#rm tmp-intercontact*
